// 获取当前device
function getDevice(bool) {
    let width = $(window).width();
    let height = $(window).height();
    if (width / height < 1 && width < 768) {
        return bool ? "phone" : "pc";
    } else {
        return bool ? "pc" : "phone";
    }
}

let timer = null;
let initDevice = getDevice(true)
$(window).resize(function() {
    clearInterval(timer);
    timer = setTimeout(() => {
        changeDevice();
    }, 500)
});

// 自适应网页大小改变device参数
function changeDevice() {
    let href = window.location.href;
    let search = window.location.search;
    let device = getDevice(false);
    if (device != initDevice) return;
    function isDevice(oldDevice, newDevice) {
        if (search.indexOf(`device=${oldDevice}`) >= 0) {
            window.location.href = href.replace(`device=${oldDevice}`, `device=${newDevice}`);
        } else if (search == '') {
            window.location.href = href + `?device=${newDevice}`;
        } else {
            window.location.href = href + `&device=${newDevice}`;
        }
    }
    if ($(window).width() >= $(window).height()) {
        if (device == 'phone') {
            isDevice(device, 'pc');
        }
    } else {
        if (device == 'pc') {
            isDevice(device, 'phone');
        } else if (device == 'kanban') {
            isDevice(device, 'phone');
        }
    }
}